﻿<UserControl x:Class="WXE.Internal.Tools.ConfigEditor.XMLEditorModule.Views.TreeEditorView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:local="clr-namespace:WXE.Internal.Tools.ConfigEditor.Common"
             xmlns:views="clr-namespace:WXE.Internal.Tools.ConfigEditor.XMLEditorModule.Views"
             xmlns:xmlNS="clr-namespace:System.Xml;assembly=System.Xml"
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
              mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300" Name="loaderWindow"  >
    <UserControl.Resources>
        <xmlNS:XmlNodeType x:Key="xmlNode">
           
        </xmlNS:XmlNodeType>
        <local:AddChildVisibilityConverter x:Key="AddChildVisibilityConverter"/>
        <local:RemoveChildVisibilityConverter x:Key="RemoveChildVisibilityConverter"/>
        <local:XmlAttributesToLableConverter x:Key="XmlAttributesToLableConverter"/>
        <HierarchicalDataTemplate x:Key="NodeTemplate">
            <StackPanel Orientation="Horizontal">
                <TextBlock x:Name="text" Text="{Binding Path=Value}">
                </TextBlock>
                <TextBlock Margin="5,0,0,0"  Foreground="Red" Text="{Binding Path=Attributes, Converter={StaticResource XmlAttributesToLableConverter}}">
                </TextBlock>
            </StackPanel>
            <HierarchicalDataTemplate.ItemsSource>
                <Binding XPath="child::node()" />
            </HierarchicalDataTemplate.ItemsSource>

            <HierarchicalDataTemplate.Triggers>
                <DataTrigger Binding="{Binding Path=NodeType}" Value="Text">
                    <Setter TargetName="text" Property="Text" Value="{Binding Path=Value}"></Setter>
                </DataTrigger>
                <DataTrigger Binding="{Binding Path=NodeType}" Value="Element">
                    <Setter TargetName="text" Property="Text" Value="{Binding Path=Name}"></Setter>
                </DataTrigger>
                <DataTrigger Binding="{Binding Path=NodeType}" Value="Comment">
                    <!--<Setter TargetName="text" Property="Visibility" Value="Collapsed"></Setter>-->
                    <Setter TargetName="text" Property="Text" Value="Comments"></Setter>
                </DataTrigger>
            </HierarchicalDataTemplate.Triggers>
        </HierarchicalDataTemplate>


        <XmlDataProvider x:Key="xmlDataProvider"></XmlDataProvider>
        <local:TreeViewHeightConverter x:Key="TreeViewHeightConverter"/>
    </UserControl.Resources>
   
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="32" />
            <RowDefinition Height="*" />
            <RowDefinition Height="50" />
        </Grid.RowDefinitions>
        <Grid Grid.Row="0" Background="Black">

            <StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center">
                <TextBlock Text="xPath:" Margin="10,0,0,0" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="LightGray" >
                </TextBlock>
                <TextBox x:Name="searchTextBox" Text="{Binding Path=SelectedNodeXpath}" Background="LightGray" Width="500" Height="25" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="3,0,0,0"></TextBox>
                <Button IsDefault="True" x:Name="searchButton" Content="Search" Height="30" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="5,0,0,0" Command="{Binding Path=FindElementCommand}" CommandParameter="{Binding Path=SelectedNodeXpath}" ></Button>
            </StackPanel>
        </Grid>
        <Grid Grid.Row="1" Margin="0,0,0,0">

            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="6*"></ColumnDefinition>
                <ColumnDefinition Width="5"></ColumnDefinition>
                <ColumnDefinition Width="5*"></ColumnDefinition>
            </Grid.ColumnDefinitions>
       
            <TreeView Name="xmlTreeView" Background="LightYellow"
                  ItemsSource="{Binding Source={StaticResource xmlDataProvider}, XPath=*}"
                  ItemTemplate= "{StaticResource NodeTemplate}" TreeViewItem.Selected="xmlTreeView_Selected" >
                <TreeView.ItemContainerStyle>
                    <Style TargetType="{x:Type TreeViewItem}">
                        <EventSetter Event="TreeViewItem.PreviewMouseRightButtonDown" Handler="TreeViewItem_PreviewMouseRightButtonDown"/>
                        <Setter Property="IsExpanded" Value="True"/>
                        <!--<Setter Property="IsSelected" Value="{Binding Path=SelectedElement}"/>-->
                    </Style>
                </TreeView.ItemContainerStyle>
            </TreeView>
         
            <GridSplitter 
                Background="Gray" 
                Grid.Column="1" 
                Height="Auto" Width="Auto" 
                HorizontalAlignment="Stretch"
                VerticalAlignment="Stretch"
                Cursor="SizeWE"/>

            <Grid Grid.Column="2"  Background="LightBlue">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="25"/>
                </Grid.RowDefinitions >
                <ListBox Grid.Row="0" Background="LightBlue"
                    ItemsSource="{Binding Path=SelectedElement.Children}"                
                 >
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <!--<ScrollViewer>-->
                            <StackPanel Orientation="Horizontal" ScrollViewer.CanContentScroll="True" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto">
                                <CheckBox HorizontalAlignment="Left" VerticalAlignment="Center" IsChecked="{Binding Path=IsSelected}" Margin="2,0,2,0"></CheckBox>
                                <TextBox FontSize="13" FontWeight="SemiBold" TextWrapping="NoWrap" FontFamily="Verdana" Foreground="Red" Name="nameText"  Text="{Binding Path=DataModel.Name, Mode=OneWay}" Margin="1,2,1,2" Width="220" Background="Transparent" IsReadOnly="True" IsReadOnlyCaretVisible="True"></TextBox>
                                <TextBox Background="AliceBlue"  TextWrapping="NoWrap" MinWidth="310" Width="310"   Name="valueText" Text="{Binding Path=DataModel.Value}" Margin="5,2,1,2" ></TextBox>
                                
                            </StackPanel>
                            <!--</ScrollViewer>-->
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
                <StackPanel Orientation="Horizontal"  Grid.Row="1" HorizontalAlignment="Center">

                    <Button x:Name="btnAddAttribute" Content="Add"  ToolTip="Add" Margin="5,0,5,0" 
                            Width="50" Height="25" HorizontalAlignment="Left"  
                            Command="{Binding Path=SelectedElement.AddAttributeCommand}" Visibility="Collapsed"
                           CommandParameter="{StaticResource xmlNode}"
                            ></Button>

                    <Button  x:Name="btnRemoveAttribute"  Content="Remove" ToolTip="Remove" Margin="5,0,5,0" Width="50" Height="25"
                              Command="{Binding Path=SelectedElement.RemoveChildrenCommand}"
                             Visibility="{Binding Path=SelectedElement.DataModel, Converter={StaticResource RemoveChildVisibilityConverter}}">
                    </Button>
                </StackPanel>
            </Grid>
        </Grid>

        <Grid Grid.Row="2">
            <StatusBar  Background="Black" VerticalAlignment="Top">
                <StatusBarItem>
                    <TextBlock Text="{Binding Path=Path}" Foreground="LightGray" ></TextBlock>
                </StatusBarItem>
            </StatusBar>        
        </Grid>
    </Grid>
    <!--Visibility="{Binding Path=SelectedElement.DataModel, Converter={StaticResource AddChildVisibilityConverter}}"-->


</UserControl>
